package com.yiyibook.util;

import org.apache.commons.lang3.StringUtils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * 〈功能简述〉
 *
 * @author xun.gong@hand-china.com
 * @date 2019/10/15
 */
public class OrderNumber {

    public static String setOrderNumber(String orderNumber){
        String localDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        if(orderNumber == null){
            orderNumber = "ON" + localDate + "0001";
        }else {
            String s = orderNumber.substring(2, 10);
            if(localDate.equals(s)){
                orderNumber = "ON" + s + StringUtils.leftPad(String.valueOf((Integer.parseInt(orderNumber.substring(10)) + 1)), 4,"0");
            }else {
                orderNumber = "ON" + localDate + "0001";
            }
        }
        return orderNumber;
    }
}
